package com.yanqu.road.entity.autodata.hotpotjump;

import java.util.ArrayList;
import java.util.List;

public class HotpotJumpUnit {
    private int id;
    private int configId;
    private int level;
    private int atk;
    private HotpotJumpGrid headPos;
    private List<HotpotJumpGrid> bodyPos = new ArrayList<>();
    private int exp; //死亡提供的经验
    private int createRound; //生成的回合

    public HotpotJumpUnit() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getConfigId() {
        return configId;
    }

    public void setConfigId(int configId) {
        this.configId = configId;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    public HotpotJumpGrid getHeadPos() {
        return headPos;
    }

    public void setHeadPos(HotpotJumpGrid headPos) {
        this.headPos = headPos;
    }

    public List<HotpotJumpGrid> getBodyPos() {
        return bodyPos;
    }

    public void setBodyPos(List<HotpotJumpGrid> bodyPos) {
        this.bodyPos = bodyPos;
    }

    public int getExp() {
        return exp;
    }

    public void setExp(int exp) {
        this.exp = exp;
    }

    public int getCreateRound() {
        return createRound;
    }

    public void setCreateRound(int createRound) {
        this.createRound = createRound;
    }

    public static List<HotpotJumpUnit> cloneList(List<HotpotJumpUnit> units) {
        List<HotpotJumpUnit> list = new ArrayList<>();
        for (HotpotJumpUnit unit : units) {
            list.add(unit.clone());
        }
        return list;
    }

    public HotpotJumpUnit clone() {
        HotpotJumpUnit clone = new HotpotJumpUnit();
        clone.id = this.id;
        clone.configId = this.configId;
        clone.level = this.level;
        clone.atk = this.atk;
        clone.headPos = this.headPos.clone();
        for (HotpotJumpGrid grid : this.bodyPos) {
            clone.bodyPos.add(grid.clone());
        }
        clone.exp = this.exp;
        clone.createRound = this.createRound;

        return clone;
    }

    public HotpotJumpGrid findGridByAll(int x, int y) {
        if (headPos.getX() == x && headPos.getY() == y) {
            return headPos;
        }
        for (HotpotJumpGrid grid : bodyPos) {
            if (grid.getX() == x && grid.getY() == y) {
                return grid;
            }
        }
        return null;
    }

    public boolean isDead() {
        return headPos.getHp() <= 0;
    }
}
